package com.crm.reports;

import java.awt.Desktop;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanArrayDataSource;

import org.apache.log4j.Logger;

import com.crm.beans.QuotParts;

public class JRQuotation {

	private final static Logger logger=Logger.getLogger(JRQuotation.class.getName());
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		String refno="KK/CP/1/19-12-2011";
		  Map parameters = new HashMap();
		  parameters.put("logo", "D:/deploy/logos/KK.gif");
		  parameters.put("quoteNo", "KK/CP/1/12-09-2012");
		  parameters.put("customer", "THE PURCHASE MANAGER,\n" +
		  		"ELECTRONIC CORPORATION OF INDIA,\n" +
		  		"ECIL POST ,\n" +
		  		"HYDERABAD \n"+
		  		"500072");
		  parameters.put("from", "KKCircuits & Equipments");
		  parameters.put("enqNo", "bhel/sjlf/CP/1/19-12-2011");
		  //parameters.put("refNo", "KK/CP/1/19-12-2011");
		  parameters.put("date", "19-12-2011");
		  parameters.put("subject", "This Is Subject");
		  parameters.put("quotid", "KKCE/123");
		  parameters.put("total", "10000");
		  parameters.put("footer", "Best Regards \n Thanks & Regards," +
		  		"Sainath");
		  parameters.put("priceword", "ten thousand only");
		  parameters.put("subject", "Please Find The Below Quotation");
		  parameters.put("terms",
				  "1 Vat @4% EXTRA.\n" +
				  "2 Validity: 30DAYS \n" +
				  "3 Waranty: NOT APPLICABLE\n" +
				  "4 Payment:  100% within 15 Days from the date of receipt of material at your stores,else interest @ 2.5%/month needs to be paid by your organisation\n" +
				  "5  Prices are valid for quoted quantities only.\n" +
				  "6  Quoted lead time is as of now only.\n" +
				  "7 Order should be placed on: KK Circuits & equipments\n"+
				  "8 Order should be placed on: KK Circuits & equipments\n"+
				  "9 Order should be placed on: KK Circuits & equipments\n"+
				  "10 Order should be placed on: KK Circuits & equipments\n"+
				  "11 Order should be placed on: KK Circuits & equipments\n"+
				  "12 Order should be placed on: KK Circuits & equipments\n"+
				  "13 Order should be placed on: KK Circuits & equipments\n"+
				  "14 Order should be placed on: KK Circuits & equipments\n"+
				  "15 Order should be placed on: KK Circuits & equipments\n"+
				  "16 Order should be placed on: KK Circuits & equipments\n"+
				  "17 Order should be placed on: KK Circuits & equipments\n"+
				  "18 Order should be placed on: KK Circuits & equipments\n"+
				  "19 Order should be placed on: KK Circuits & equipments\n"+
				  "20 Order should be placed on: KK Circuits & equipments\n"+
				  "21 Order should be placed on: KK Circuits & equipments\n"+
				  "22 Order should be placed on: KK Circuits & equipments\n"+
				  "23 Order should be placed on: KK Circuits & equipments\n"+
				  "24 Order should be placed on: KK Circuits & equipments\n"+
				  "25 Order should be placed on: KK Circuits & equipments\n"+
				  "26 Order should be placed on: KK Circuits & equipments\n"+
				  "27 Order should be placed on: KK Circuits & equipments\n"+
				  "28 Order should be placed on: KK Circuits & equipments\n"+
				  "29 Order should be placed on: KK Circuits & equipments\n"+
				  "30 Order should be placed on: KK Circuits & equipments\n"+
				  "31 Order should be placed on: KK Circuits & equipments\n"+
				  "32 Order should be placed on: KK Circuits & equipments\n"+
				  "33 Order should be placed on: KK Circuits & equipments\n"+
				  "34 Order should be placed on: KK Circuits & equipments\n"+
				  "35 Order should be placed on: KK Circuits & equipments\n"+
				  "36 Order should be placed on: KK Circuits & equipments\n"+
				  "37 Order should be placed on: KK Circuits & equipments\n"+
				  "38 Order should be placed on: KK Circuits & equipments\n"+
				  "39 Order should be placed on: KK Circuits & equipments\n"+
				  "40 Order should be placed on: KK Circuits & equipments\n"
				  );
		  QuotParts qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er232sdsadasdasdasdasd3";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="1";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  List<QuotParts> l=new ArrayList<QuotParts>();
		  l.add(qp);
		  
		   qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="2";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="3";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="4";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="5";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="6";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="7";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="8";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="9";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="10";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="11";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="12";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="13";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="14";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="15";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="16";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="17";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="18";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="19";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="20";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  qp=new QuotParts();
		  qp.delivery="2-3 weeks";
		  qp.extPrice="1000";
		  qp.make="honda";
		  qp.moq="2";
		  qp.partNo="er2323";
		  qp.qty="10";
		  qp.unitPrice="100";
		  qp.sno="21";
		  qp.desc="abcd";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		runReport("D:/sainath/work/crmWeb/WebContent/WEB-INF/classes/reports/newquot.jasper",refno, parameters, l.toArray());
		runTechReport("D:/sainath/work/crmWeb/WebContent/WEB-INF/classes/reports/newtechquot.jasper",refno,parameters, l.toArray());
		}

	public static void runReport(String repName,String refno,Map params,Object[] qparts) throws Exception{
		  long start = System.currentTimeMillis();
		  //Preparing parameters
		   
		 JasperPrint print =JasperFillManager.fillReport(repName,params,new JRBeanArrayDataSource(qparts));
		 OutputStream output = new FileOutputStream(new File(" Price Bid.pdf"));
		  try {
			JasperExportManager.exportReportToPdfStream(print, output);
		} catch (net.sf.jasperreports.engine.JRException e) {
			e.printStackTrace();
		} 
		  output.close();
		  Desktop.getDesktop().open(new File(" Price Bid.pdf"));
		  
		  System.err.println("Filling time : " + (System.currentTimeMillis() - start));
		
	}
	public static void runTechReport(String repName,String refno,Map params,Object[] qparts) throws Exception{
		long start = System.currentTimeMillis();
		
		
		JasperPrint print =JasperFillManager.fillReport(repName,params,new JRBeanArrayDataSource(qparts));

		
		
		 OutputStream output = new FileOutputStream(new File(" Technical Bid.pdf"));
		JasperExportManager.exportReportToPdfStream(print, output); 
		output.close();
		
		Desktop.getDesktop().open(new File(" Technical Bid.pdf"));
		System.err.println("Filling time : " + (System.currentTimeMillis() - start));
		
	}
	public static void runWordReport(String repName,String refno,Map params,Object[] qparts) throws Exception{
		  long start = System.currentTimeMillis();
		  //Preparing parameters
		   
		 JasperPrint print =JasperFillManager.fillReport(repName,params,new JRBeanArrayDataSource(qparts));
		 
		 
		 
		 OutputStream output = new FileOutputStream(new File(" Price Bid.pdf"));
		  try {
			JasperExportManager.exportReportToPdfStream(print, output);
		} catch (net.sf.jasperreports.engine.JRException e) {
			e.printStackTrace();
		} 
		  output.close();
		  Desktop.getDesktop().open(new File(" Price Bid.pdf"));
		  
		  System.err.println("Filling time : " + (System.currentTimeMillis() - start));
		
	}
}
